package tech.runchen.gz5055.oms.common.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.runchen.gz5055.oms.common.exception.RRException;
import tech.runchen.gz5055.oms.common.utils.Result;
import tech.runchen.gz5055.oms.common.utils.SecurityUtils;
import tech.runchen.gz5055.oms.common.utils.SpringUtils;
import tech.runchen.gz5055.oms.security.model.LoginUser;

import java.util.Objects;

/**
 * @author zzj
 */
public abstract class AbstractController {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected Result toResult(boolean ret) {
        return ret ? Result.success() : Result.error();
    }

    protected Result toResult(boolean ret, String message) {
        return ret ? Result.success() : Result.error(message);
    }

    protected Result toResult(Object data, String message) {
        return Objects.nonNull(data) ? Result.success(data) : Result.error(message);
    }

    protected LoginUser getLoginUser() {
        return SecurityUtils.getLoginUser();
    }

    protected Long getUserId() {
        return getLoginUser().getUserId();
    }

    protected String getUserName() {
        return getLoginUser().getUsername();
    }

    protected String getNickName() {
        return getLoginUser().getUser().getNickName();
    }
}
